import 'package:flutter/material.dart';
import 'package:sports_new/resources/colours.dart';
import 'package:sports_new/utils/utils.dart';

class AiItemEntity {
  int? aiMatchId;
  int? priceId;
  String? price;
  String? aiIndex;
  String? aiIndexName;
  List<AiOption>? aiOption;
  int? planTotal;
  List<PlanCount>? planCounts;
  String? aiResult;
  String? content;
  int? guestId;
  String? guestLogo;
  String? guestName;
  String? guestRanking;
  int? guestScore90;
  int? homeId;
  String? homeLogo;
  String? homeName;
  String? homeRanking;
  int? homeScore90;
  int? isOpen;
  int? leagueId;
  String? leagueName;
  int? level;
  int? matchId;
  String? matchNo;
  String? dcMatchNo;
  String? jcMatchNo;
  String? sfcMatchNo;
  String? matchTime;
  int? status;

  AiItemEntity(
      {this.aiMatchId,
        this.priceId,
        this.price,
        this.aiIndex,
        this.aiIndexName,
        this.aiOption,
        this.planTotal,
        this.planCounts,
        this.aiResult,
        this.content,
        this.guestId,
        this.guestLogo,
        this.guestName,
        this.guestRanking,
        this.guestScore90,
        this.homeId,
        this.homeLogo,
        this.homeName,
        this.homeRanking,
        this.homeScore90,
        this.isOpen,
        this.leagueId,
        this.leagueName,
        this.level,
        this.matchId,
        this.matchNo,
        this.dcMatchNo,
        this.jcMatchNo,
        this.sfcMatchNo,
        this.matchTime,
        this.status});

  AiItemEntity.fromJson(Map<String, dynamic> json) {
    aiMatchId = json['aiMatchId'];
    priceId = json['priceId'];
    price = json['price'];
    aiIndex = json['aiIndex'];
    aiIndexName = json['aiIndexName'];
    if (json['aiOption'] != null) {
      aiOption = <AiOption>[];
      json['aiOption'].forEach((v) {
        aiOption!.add(new AiOption.fromJson(v));
      });
    }
    planTotal = json['planTotal'];
    if(json['planCnt']!= null){
      planCounts = <PlanCount>[];
      json['planCnt']['playBeans'].forEach((v) {
        planCounts!.add(new PlanCount.fromJson(v));
      });
    }
    aiResult = json['aiResult'];
    content = json['content'];
    guestId = json['guestId'];
    guestLogo = json['guestLogo'];
    guestName = json['guestName'];
    guestRanking = json['guestRanking'];
    guestScore90 = json['guestScore90'];
    homeId = json['homeId'];
    homeLogo = json['homeLogo'];
    homeName = json['homeName'];
    homeRanking = json['homeRanking'];
    homeScore90 = json['homeScore90'];
    isOpen = json['isOpen'];
    leagueId = json['leagueId'];
    leagueName = json['leagueName'];
    level = json['level'];
    matchId = json['matchId'];
    matchNo = json['matchNo'];
    dcMatchNo = json['dcMatchNo'];
    jcMatchNo = json['jcMatchNo'];
    sfcMatchNo = json['sfcMatchNo'];
    matchTime = json['matchTime'];
    status = json['status'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['aiMatchId'] = this.aiMatchId;
    data['priceId'] = this.priceId;
    data['price'] = this.price;
    data['aiIndex'] = this.aiIndex;
    data['aiIndexName'] = this.aiIndexName;
    if (this.aiOption != null) {
      data['aiOption'] = this.aiOption!.map((v) => v.toJson()).toList();
    }
    data['planTotal'] = this.planTotal;
    if(this.planCounts!= null){
      data['planCnt'] = this.planCounts!.map((v) => v.toJson()).toList();
    }
    data['aiResult'] = this.aiResult;
    data['content'] = this.content;
    data['guestId'] = this.guestId;
    data['guestLogo'] = this.guestLogo;
    data['guestName'] = this.guestName;
    data['guestRanking'] = this.guestRanking;
    data['guestScore90'] = this.guestScore90;
    data['homeId'] = this.homeId;
    data['homeLogo'] = this.homeLogo;
    data['homeName'] = this.homeName;
    data['homeRanking'] = this.homeRanking;
    data['homeScore90'] = this.homeScore90;
    data['isOpen'] = this.isOpen;
    data['leagueId'] = this.leagueId;
    data['leagueName'] = this.leagueName;
    data['level'] = this.level;
    data['matchId'] = this.matchId;
    data['matchNo'] = this.matchNo;
    data['dcMatchNo'] = this.dcMatchNo;
    data['jcMatchNo'] = this.jcMatchNo;
    data['sfcMatchNo'] = this.sfcMatchNo;
    data['matchTime'] = this.matchTime;
    data['status'] = this.status;
    return data;
  }
}

class AiOption {
  bool? hit;
  String? name;
  String? odds;
  String? option;

  AiOption({this.hit, this.name, this.odds, this.option});

  AiOption.fromJson(Map<String, dynamic> json) {
    hit = json['hit'];
    name = json['name'];
    odds = json['odds'];
    option = json['option'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['hit'] = this.hit;
    data['name'] = this.name;
    data['odds'] = this.odds;
    data['option'] = this.option;
    return data;
  }
}

class PlanCount {
  ChangeCnt? changeCnt;
  int? playType;
  String? line;
  String? playTypeName;

  PlanCount({this.changeCnt, this.playType, this.line, this.playTypeName});

  PlanCount.fromJson(Map<String, dynamic> json) {
    if (json['changeCnt'] != null) {
      changeCnt = new ChangeCnt.fromJson(json['changeCnt']);
    }
    playType = json['playType'];
    line = json['line'];
    playTypeName = json['playTypeName'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.changeCnt != null) {
      data['changeCnt'] = this.changeCnt!.toJson();
    }
    data['playType'] = this.playType;
    data['line'] = this.line;
    data['playTypeName'] = this.playTypeName;
    return data;
  }
}

class ChangeCnt {
  CountType? p;
  CountType? s;
  CountType? pf;
  CountType? f;
  CountType? sp;

  ChangeCnt({this.p, this.s, this.pf, this.f, this.sp});

  ChangeCnt.fromJson(Map<String, dynamic> json) {
    p = json['p'] != null ? new CountType.fromJson(json['p']) : null;
    s = json['s'] != null ? new CountType.fromJson(json['s']) : null;
    pf = json['pf'] != null ? new CountType.fromJson(json['pf']) : null;
    f = json['f'] != null ? new CountType.fromJson(json['f']) : null;
    sp = json['sp'] != null ? new CountType.fromJson(json['sp']) : null;
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    if (this.p != null) {
      data['p'] = this.p!.toJson();
    }
    if (this.s != null) {
      data['s'] = this.s!.toJson();
    }
    if (this.pf != null) {
      data['pf'] = this.pf!.toJson();
    }
    if (this.f != null) {
      data['f'] = this.f!.toJson();
    }
    if (this.sp != null) {
      data['sp'] = this.sp!.toJson();
    }
    return data;
  }
}

extension ChangeCntExtension on ChangeCnt{
  List<CountType?> get values => [s,sp,p,pf,f];
}

class CountType {
  int? total;
  String? typeName;
  String? type;

  CountType({this.total, this.typeName, this.type});

  CountType.fromJson(Map<String, dynamic> json) {
    total = json['total'];
    typeName = json['typeName'];
    type = json['type'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['total'] = this.total;
    data['typeName'] = this.typeName;
    data['type'] = this.type;
    return data;
  }
}

extension CountTypeExtension on CountType{
  Color get color {
    switch(type){
      case "s":
        return total.hasValue?Colours.main:Colours.greyCC;
      case "sp":
        return total.hasValue?const Color(0xFFF1A003):Colours.greyCC;
      case "p":
        return total.hasValue?Colours.blue2766D6:Colours.greyCC;
      case "pf":
        return total.hasValue?const Color(0xFFACC801):Colours.greyCC;
      case "f":
        return total.hasValue?const Color(0xFF29A878):Colours.greyCC;
      default:
        return Colours.greyCC;
    }
  }
}
